var app = new Vue({
    el: '#app',
    data: {
        consignees: "",
        areaShow: false, //区域选择区块的显示和隐藏
        areas: [], //区域数据模板
        /*区域tab*/
        tabArea1: "",
        tabArea2: "请选择",
        tabArea3: "请选择",
        tabArea4: "请选择",
        /*区域tab的显示和隐藏*/
        areaTab1: true,
        areaTab2: false,
        areaTab3: false,
        areaTab4: false,
        /*点击区域tab时需要的parentCode*/
        parentCode2: "",
        parentCode3: "",
        /*点击区域tab时需要显示的areaName*/
        goName2: "",
        goName3: "",
        /*tab样式控制*/
        isCurr1: true,
        isCurr2: false,
        isCurr3: false,
        isCurr4: false,
        /*收获区域名称，省市乡镇分开*/
        provinceName: "请选择收货区域",
        cityName: "",
        countyName: "",
        villageName: "",
        /*获取选择的区域*/
        provinceId: window.historyPrivinceId,
        cityId: window.historyCityId,
        countyId: window.historyCountyId,
        villageId: window.historyVillageId,
        provinceCode: window.historyPrivinceCode,
        cityCode: window.historyCityCode,
        countyCode: window.historyCountyCode,
        villageCode: window.historyVillageCode,
        selectName:"北京",
        isUpdataAddress: true,
    },
    mounted: function () {
        this.province(this.selectName);
    },
    methods: {
        isUpdataAddressFn(){
            let inquire_state= window.inquiry_status;
            // console.log(inquire_state)
            if(inquire_state=="20"||inquire_state=="30"){
                this.isUpdataAddress = false;
            }else {
                this.isUpdataAddress = true;
            }
            // console.log(this.isUpdataAddress)
        },
        initAddress(){
            this.isCurr1 = true;
            this.isCurr2 = false;
            this.isCurr3 = false;
            this.isCurr4 = false;
            this.provinceName = "请选择收货区域";
            this.cityName = "";
            this.countyName = "";
            this.villageName = "";
            this.tabArea1 = "";
            this.tabArea2 = "请选择";
            this.tabArea3 = "请选择";
            this.tabArea4 = "请选择";
            this.areaTab1 = true;
            this.areaTab2 = false;
            this.areaTab3 = false;
            this.areaTab4 = false;
        },
        /*关闭选择框*/
        closeArea(){
            document.getElementById("provinceName").innerHTML = window.historyProvinceName;
            document.getElementById("cityName").innerHTML = window.historyCityName;
            document.getElementById("countyName").innerHTML = window.historyDistrictName;
            if(document.getElementById("villageName").innerHTML!=""){
                document.getElementById("villageName").innerHTML = window.historyStreetName;
            }
            this.initAddress();
            this.province(this.selectName);
            this.areaShow = false;
            var vueBox = document.getElementById("vueBox");
            vueBox.style.display = "none";
            var notVueBox = document.getElementById("notVueBox");
            notVueBox.style.display = "block";
            window.updataGoodsList(window.historyCityCode);
        },
        /*点击弹出区域选择框*/
        isAreaShow() {
            this.isUpdataAddressFn();
            if(this.isUpdataAddress){
                this.areaShow = !this.areaShow;
                if(this.areaShow == false){
                    document.getElementById("provinceName").innerHTML = window.historyProvinceName;
                    document.getElementById("cityName").innerHTML = window.historyCityName;
                    document.getElementById("countyName").innerHTML = window.historyDistrictName;
                    if(document.getElementById("villageName").innerHTML!=""){
                        document.getElementById("villageName").innerHTML = window.historyStreetName;
                    }
                    var vueBox = document.getElementById("vueBox");
                    vueBox.style.display = "none";
                    var notVueBox = document.getElementById("notVueBox");
                    notVueBox.style.display = "block";
                    this.initAddress();
                    this.province(this.selectName);
                    // this.selectName = this.provinceName;
                    window.updataGoodsList(window.historyCityCode);
                }else {
                    var vueBox = document.getElementById("vueBox");
                    vueBox.style.display = "block";
                    var notVueBox = document.getElementById("notVueBox");
                    notVueBox.style.display = "none";
                }
                let that = this;
                document.addEventListener('click',function(e){
                    if(e.target.parentNode.className!="list clearfix" && e.target.parentNode.className!="tab clearfix" && e.target.parentNode.className !="area_list" && e.target.parentNode.className != "divHide" && e.target.parentNode.className != "inp_area_box"){
                        if(that.areaShow != false){
                            document.getElementById("provinceName").innerHTML = window.historyProvinceName;
                            document.getElementById("cityName").innerHTML = window.historyCityName;
                            document.getElementById("countyName").innerHTML = window.historyDistrictName;
                            if(document.getElementById("villageName").innerHTML!=""){
                                document.getElementById("villageName").innerHTML = window.historyStreetName;
                            }
                            var vueBox = document.getElementById("vueBox");
                            vueBox.style.display = "none";
                            var notVueBox = document.getElementById("notVueBox");
                            notVueBox.style.display = "block";
                            that.initAddress();
                            that.province(that.selectName);
                            // that.selectName = that.provinceName;
                            that.areaShow = false;
                            window.updataGoodsList(window.historyCityCode);
                        }
                    }
                });
            }

        },
        /*加载获取省份*/
        province(areaName) {
            let that = this;
            $.ajax({
                type: "POST",
                url: root.replaceInter.replace_adminGetAddByParam,
                cache: false,  //禁用缓存
                dataType: "json",
                data: {
                    memberId: '10258',
                    level: '101'
                },  //传入组装的参数
                success: function (response) {
                    if (response.errorCode == 1) {
                        that.tabArea1 = areaName;
                        that.areas = response.list;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    // alert(XMLHttpRequest);
                }
            });
        },
        /*点击选择区域（省市县乡）*/
        getArea(level, parentCode, areaName, isTab, addressId) {
            var nextlevel;
            let that = this;
            /*判断是否tab点击*/
            if (isTab == "tab") {
                var nextlevel = String(level);
                if (level == "101") {
                    that.cityName = "";
                    that.countyName = "";
                    that.villageName = "";
                } else if (level == "102") {
                    that.countyName = "";
                    that.villageName = "";
                } else if (level == "103") {
                    that.villageName = "";
                }
            } else if (isTab == "noTab") {
                if (level == '101') {
                    that.provinceName = areaName;
                    that.provinceId = addressId;
                    that.provinceCode = parentCode;
                    that.cityName = "";
                    that.countyName = "";
                    that.villageName = "";
                    that.cityId = '';
                    that.countyId = '';
                    that.villageId = '';
                    that.cityCode = '';
                    that.countyCode = '';
                    that.villageCode = '';
                }
                nextlevel = String(Number(level + 1));
            }
            if (nextlevel == "105") {
                $.ajax({
                    url: root.replaceInter.replace_getAddressCorrespondWarehouse,
                    // url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getAddressCorrespondWarehouse',

                    cache: false, //禁用缓存
                    type: "POST",
                    data: {code:that.cityCode},
                    success: function(data) {
                        if(data.errorCode == "0"){
                            console.log(data.data.warehouse_code)
                            window.warehouseCode = data.data.warehouse_code;
                            window.updataGoodsList(that.cityCode,"",data.data.warehouse_code);
                        }else {
                            $.Huimodalalert(data.errorMessage,2000);
                        }
                    }
                });
                that.villageName = areaName;
                that.villageId = addressId;
                that.villageCode = parentCode;
                that.tabArea4 = areaName;
                that.isCurr1 = false;
                that.isCurr2 = false;
                that.isCurr3 = false;
                that.isCurr4 = true;
                window.historyPrivinceId = that.provinceId;
                window.historyCityId = that.cityId;
                window.historyCountyId = that.districtId;
                window.historyVillageId = that.villageId;
                window.historyPrivinceCode = that.provinceCode;
                window.historyCityCode = that.cityCode;
                window.historyCountyCode = that.countyCode;
                window.historyVillageCode = that.villageCode;
                window.provinceCode = that.provinceCode;
                window.cityCode = that.cityCode;
                window.districtCode = that.countyCode;
                window.streetCode = that.villageCode;
                window.historyProvinceName = that.provinceName;   //历史省名称
                window.historyCityName = that.cityName;   //历史市名称
                window.historyDistrictName = that.countyName;  //历史县名称
                window.historyStreetName = that.villageName;
                that.areaShow = !that.areaShow;
            } else {
                $.ajax({
                    type: "POST",
                    url: root.replaceInter.replace_adminGetAddByParam,
                    cache: false,  //禁用缓存
                    dataType: "json",
                    data: {
                        memberId: '10258',
                        level: nextlevel,
                        parentCode: parentCode,
                    },  //传入组装的参数
                    success: function (response) {
                        if (response.errorCode == 1) {
                            if (response.errorCode == 1) {
                                that.areas = response.list;
                                that.isCurr1 = true;
                                that.isCurr2 = false;
                                that.isCurr3 = false;
                                that.isCurr4 = false;
                                if (nextlevel == '102') {
                                    that.areaType = response.list.level;
                                    that.areaTab2 = true;
                                    if (isTab == "noTab") {
                                        if (that.areas.length <= 0) {
                                            that.areaShow = !that.areaShow;
                                            return false;
                                        } else {
                                            that.areaTab3 = false;
                                            that.areaTab4 = false;
                                            that.tabArea2 = "请选择";
                                        }
                                        // that.areaTab3 = false;
                                        // that.areaTab4 = false;
                                        // that.tabArea2 = "请选择";

                                    }
                                    that.isCurr1 = false;
                                    that.isCurr2 = true;
                                    that.isCurr3 = false;
                                    that.isCurr4 = false;
                                    that.tabArea1 = areaName;
                                    that.parentCode2 = parentCode;
                                    that.goName2 = areaName;
                                } else if (nextlevel == '103') {
                                    that.areaType = response.list.level;
                                    that.tabArea2 = areaName;
                                    that.areaTab3 = true;
                                    if (isTab == "noTab") {
                                        that.cityName = areaName;
                                        that.cityId = addressId;
                                        that.cityCode = parentCode;
                                        if (that.areas.length <= 0) {
                                            if(that.cityName=="钓鱼岛"){
                                                that.areaTab3 = false;
                                                that.isCurr1 = false;
                                                that.isCurr2 = true;
                                                window.historyPrivinceId = that.provinceId;
                                                window.historyCityId = that.cityId;
                                                window.historyCountyId = that.countyId;
                                                window.historyPrivinceCode = that.provinceCode;
                                                window.historyCityCode = that.cityCode;
                                                window.historyCountyCode = that.countyCode;
                                                window.historyProvinceName = that.provinceName;   //历史省名称
                                                window.historyCityName = that.cityName;   //历史市名称
                                                window.historyDistrictName = that.countyName;  //历史县名称
                                                window.historyStreetName = that.villageName;
                                                // window.updataGoodsList(that.cityCode);
                                                $.ajax({
                                                    url: root.replaceInter.replace_getAddressCorrespondWarehouse,
                                                    // url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getAddressCorrespondWarehouse',

                                                    cache: false, //禁用缓存
                                                    type: "POST",
                                                    data: {code:that.cityCode},
                                                    success: function(data) {
                                                        if(data.errorCode == "0"){
                                                            console.log(data.data.warehouse_code)
                                                            window.warehouseCode = data.data.warehouse_code;
                                                            window.updataGoodsList(that.cityCode,"",data.data.warehouse_code);
                                                        }else {
                                                            $.Huimodalalert(data.errorMessage,2000);
                                                        }
                                                    }
                                                });
                                            }
                                            that.areaShow = !that.areaShow;
                                            return false;
                                        } else {
                                            that.areaTab4 = false;
                                            that.tabArea3 = "请选择";
                                        }
                                        that.areaTab4 = false;
                                        // that.tabArea3 = "请选择";
                                    }
                                    that.isCurr1 = false;
                                    that.isCurr2 = false;
                                    that.isCurr3 = true;
                                    that.isCurr4 = false;
                                    that.tabArea2 = areaName;
                                    that.parentCode3 = parentCode;
                                    that.goName3 = areaName;
                                } else if (nextlevel == '104') {
                                    that.areaType = response.list.level;
                                    that.tabArea3 = areaName;
                                    that.isCurr1 = false;
                                    that.isCurr2 = false;
                                    that.isCurr3 = true;
                                    that.isCurr4 = false;
                                    if (isTab == "noTab") {
                                        that.countyName = areaName;
                                        that.countyId = addressId;
                                        that.countyCode = parentCode;
                                        if (that.areas.length <= 0) {
                                            window.historyPrivinceId = that.provinceId;
                                            window.historyCityId = that.cityId;
                                            window.historyCountyId = that.countyId;
                                            window.historyPrivinceCode = that.provinceCode;
                                            window.historyCityCode = that.cityCode;
                                            window.historyCountyCode = that.countyCode;
                                            window.historyProvinceName = that.provinceName;   //历史省名称
                                            window.historyCityName = that.cityName;   //历史市名称
                                            window.historyDistrictName = that.countyName;  //历史县名称
                                            window.historyStreetName = that.villageName;
                                            $.ajax({
                                                url: root.replaceInter.replace_getAddressCorrespondWarehouse,
                                                // url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getAddressCorrespondWarehouse',

                                                cache: false, //禁用缓存
                                                type: "POST",
                                                data: {code:that.cityCode},
                                                success: function(data) {
                                                    if(data.errorCode == "0"){
                                                        console.log(data.data.warehouse_code)
                                                        window.warehouseCode = data.data.warehouse_code;
                                                        window.updataGoodsList(that.cityCode,"",data.data.warehouse_code);
                                                    }else {
                                                        $.Huimodalalert(data.errorMessage,2000);
                                                    }
                                                }
                                            });
                                            that.areaShow = !that.areaShow;
                                            return false;
                                        } else {
                                            that.areaTab4 = true;
                                            that.tabArea4 = "请选择";
                                        }

                                        //that.tabArea4 = "请选择";
                                    }
                                }
                            }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest);
                    }
                });
            }
        },
    },
});